<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script crossorigin src="../js/react.production.min.js"></script>
    <!-- 核心库  最先引用 -->
    <script crossorigin src="../js/react-dom.production.min.js"></script>
    <!-- 引用react-dom 用于支持react操作DOM -->
    <script crossorigin src="../js/babel.min.js"></script>
    <!-- 引入babel 用于将jsx转为js -->
    <script crossorigin src="../js/prop-types.js"></script>
    <!-- 对组件标签进行限制 -->
    <title>学习react</title>
</head>

<body>
    <div id="test"></div>
    <div id="test1"></div>
    <script type="text/babel">

        class MyDemo extends React.Component {
            MyRef = React.createRef() // React.createRef()调用后返回一个容器 可以存储被ref所标识的节点 该容器是专人专用
            // React.createRef() 是react 当前最推荐的一个方式
            render() {
                const { name, age } = this.props
                return (
                    <div>
                        <input ref="ipt1" placeholder="点击按钮提示数据" />&nbsp;
                        <input ref={this.MyRef} placeholder="12332" />&nbsp;
                        <button onClick={this.handleClick}>点我提示数据</button>&nbsp;
                        <input onBlur={this.handleClick1} ref={a => this.ipt2 = a} placeholder="失去焦点提示数据" />
                    </div>
                )
            }
            handleClick = () => {
                const { ipt1 } = this.refs
                console.log(ipt1.value);
                console.log(this.MyRef.current.value);
            }
            handleClick1 = () => {
                const { ipt2 } = this
                console.log(ipt2.value);
            }
        }
        ReactDOM.render(<MyDemo name='tom1' />, document.getElementById("test"));
    </script>
</body>

</html>